package com.zwd.cases.demo.utilstest;

import com.zwd.cases.utils.CommonUtil;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Description TODO
 * @Author zhengwd
 * @Date 2022/10/28 16:49
 **/
@Slf4j
public class Demo2 {

    public static void main(String[] args) {
        String result = "FALSE";

        // 就诊日期
        AppointRegLogVO appointRegLogVO = new AppointRegLogVO();

        String formatYmdStr = "2022-10-28";
        Date medDate2 = CommonUtil.strTimeToDateYmd(formatYmdStr);
        System.out.println(medDate2);
        appointRegLogVO.setMedDate(medDate2);


//        String formatYmdStr2 = "2022-10-28 8:19:12";
        String formatYmdStr2 = "2022-10-28 17:11:00";
        Date medEndTime2 = CommonUtil.strTimeToDateYmdHms(formatYmdStr2);
        System.out.println(medEndTime2);
        appointRegLogVO.setMedEndTime(medEndTime2);


        Date medDate = appointRegLogVO.getMedDate();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        String nowDateStr = sdf.format(new Date());
        String medDateStr = sdf.format(medDate);
        // 日期相同 且 就诊时间小于就诊开始时间 可退
        if (nowDateStr.equals(medDateStr)) {
            // 就诊结束时间
            Date medEndTime = appointRegLogVO.getMedEndTime();
            SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss");
            String beginTimeStr = format.format(new Date());
            String medEndTimeStr = format.format(medEndTime);
            try {
                long second = (format.parse(medEndTimeStr).getTime() - format.parse(beginTimeStr).getTime())/1000;
                log.info("山东威海市中心医院本部院区当日挂号-时间差：{}", second);
                // 就诊结束前可取消
                if (second >= 0) {
                    result = "TRUE";
                }
            } catch (Exception e) {
                log.error("山东威海市中心医院本部院区当日挂号取消规则校验出错：{}", e.getStackTrace());
            }
        }
        System.out.println(result);
    }
}

@Data
class AppointRegLogVO {
    private Date medEndTime;
    private Date medDate;
}